package com.neusoft.elmboot.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.neusoft.elmboot.po.CreditTrans;

@Mapper
public interface CreditTransMapper {

	@Insert("insert into credittrans(userId,channelId,eventId,credit,createTime,expiredTime,leftVal) values(#{userId},#{channelId},#{eventId},#{credit},#{createTime},#{expiredTime},#{leftVal})")
	@Options(useGeneratedKeys = true,keyProperty="id",keyColumn="id")
	public int addCredit(CreditTrans creditTrans);
	
	@Select("select * from credittrans where userId=#{userId}")
	public List<CreditTrans> getCredit(String userId);
	
	@Update("update credittrans set leftVal=0 where id=#{id}")
	public int invalid(int id);
	
	@Select("select * from credittrans where userId=#{userId} and channelId=1 order by expiredTime DESC")
	public List<CreditTrans> getaddingTrans(String userId);
	
	@Select("select * from credittrans where userId=#{userId} and channelId=0 order by createTime DESC")
	public List<CreditTrans> getusingTrans(String userId);
	
	@Select("select * from credittrans where userId=#{userId} and channelId=1")
	public List<CreditTrans> getadding(String userId);
	
	@Update("update credittrans set leftVal=leftVal-#{need} where id=#{id}")
	public int setleft(int id,int need);
	
}